package com.ruoyi.nurse.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.nurse.domain.NurseSchedule;
import com.ruoyi.nurse.service.INurseScheduleService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 护工排班Controller
 * 
 * @author ruoyi
 * @date 2025-03-26
 */
@RestController
@RequestMapping("/schedule")
public class NurseScheduleController extends BaseController
{
    @Autowired
    private INurseScheduleService nurseScheduleService;

    /**
     * 查询护工排班列表
     */
    @RequiresPermissions("nurse:schedule:list")
    @GetMapping("/list")
    public TableDataInfo list(NurseSchedule nurseSchedule)
    {
        startPage();
        List<NurseSchedule> list = nurseScheduleService.selectNurseScheduleList(nurseSchedule);
        return getDataTable(list);
    }

    /**
     * 导出护工排班列表
     */
    @RequiresPermissions("nurse:schedule:export")
    @Log(title = "护工排班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NurseSchedule nurseSchedule)
    {
        List<NurseSchedule> list = nurseScheduleService.selectNurseScheduleList(nurseSchedule);
        ExcelUtil<NurseSchedule> util = new ExcelUtil<NurseSchedule>(NurseSchedule.class);
        util.exportExcel(response, list, "护工排班数据");
    }

    /**
     * 获取护工排班详细信息
     */
    @RequiresPermissions("nurse:schedule:query")
    @GetMapping(value = "/{scheduleId}")
    public AjaxResult getInfo(@PathVariable("scheduleId") Long scheduleId)
    {
        return success(nurseScheduleService.selectNurseScheduleByScheduleId(scheduleId));
    }

    /**
     * 新增护工排班
     */
    @RequiresPermissions("nurse:schedule:add")
    @Log(title = "护工排班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NurseSchedule nurseSchedule)
    {
        return toAjax(nurseScheduleService.insertNurseSchedule(nurseSchedule));
    }

    /**
     * 修改护工排班
     */
    @RequiresPermissions("nurse:schedule:edit")
    @Log(title = "护工排班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NurseSchedule nurseSchedule)
    {
        return toAjax(nurseScheduleService.updateNurseSchedule(nurseSchedule));
    }

    /**
     * 删除护工排班
     */
    @RequiresPermissions("nurse:schedule:remove")
    @Log(title = "护工排班", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scheduleIds}")
    public AjaxResult remove(@PathVariable Long[] scheduleIds)
    {
        return toAjax(nurseScheduleService.deleteNurseScheduleByScheduleIds(scheduleIds));
    }
}
